﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp
{
    /// <summary>
    /// WordControl.xaml 的交互逻辑
    /// </summary>
    public partial class WordControl : UserControl
    {
        public WordControl()
        {
            InitializeComponent();
        }

        public static readonly DependencyProperty CharacterProperty =
            DependencyProperty.Register("Character", typeof(string), typeof(WordControl), new PropertyMetadata(""));

        public static readonly DependencyProperty PinyinProperty =
            DependencyProperty.Register("Pinyin", typeof(string), typeof(WordControl), new PropertyMetadata(""));

        public static readonly DependencyProperty ShowPinyinProperty =
            DependencyProperty.Register("ShowPinyin", typeof(bool), typeof(WordControl), new PropertyMetadata(true));

        public static readonly DependencyProperty IsSelectedProperty =
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(WordControl), new PropertyMetadata(true));
        public string Character
        {
            get => (string)GetValue(CharacterProperty);
            set => SetValue(CharacterProperty, value);
        }

        public string Pinyin
        {
            get => (string)GetValue(PinyinProperty);
            set => SetValue(PinyinProperty, value);
        }

        public bool ShowPinyin
        {
            get => (bool)GetValue(ShowPinyinProperty);
            set => SetValue(ShowPinyinProperty, value);
        }
        public bool IsSelected
        {
            get => (bool)GetValue(IsSelectedProperty);
            set => SetValue(IsSelectedProperty, value);
        }
    }
    public class BoolToBrushConverter : IValueConverter
    {
        public Brush TrueBrush { get; set; } = Brushes.Red;
        public Brush FalseBrush { get; set; } = Brushes.Transparent;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value is bool b && b ? TrueBrush : FalseBrush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;
    }
}
